import { createStore } from 'vuex'
const store = createStore({
    state() {
        return {
            count: 0
        }
    },
    mutations: {
        increment(state) {
            state.count++
        },
        decrement(state) {
            if (state.count > 0) {
                state.count--
            }

        }
    },
    getters: {//返回一个计算属性
        getCount(state) {
            return state.count + 3
        }
    },
    actions: {
        asyncIncrement({ commit }) {
            setTimeout(() => {
                commit('increment')
            }, 1000)
        },
        asyncDecrement({ commit }) {
            setTimeout(() => {
                commit('decrement')
            }, 1000)
        }
    },
})
export default store